package com.yxq.mdt.app.modules.order.prestener;


import com.yxq.mdt.app.base.BasePresenter;
import com.yxq.mdt.app.modules.order.bean.ExpressBean;
import com.yxq.mdt.app.modules.order.bean.OrderConfirmBean;
import com.yxq.mdt.app.modules.order.bean.OrderDetailBean;
import com.yxq.mdt.app.modules.order.bean.OrderListBean;
import com.yxq.mdt.app.modules.order.bean.OrderPayResultBalanceBean;
import com.yxq.mdt.app.modules.order.bean.OrderPayResultWxBean;
import com.yxq.mdt.app.modules.order.bean.OrderSubmitResult;
import com.yxq.mdt.app.modules.order.model.OrderModel;
import com.yxq.mdt.app.net.ApiModel;

public class OrderPresenter extends BasePresenter<IOrderContract.View, OrderModel> implements IOrderContract.Presenter {

    public OrderPresenter(IOrderContract.View view, OrderModel model) {
        super(view, model);
    }

    @Override
    public void preview(String address_id, String mch_list) {

        mBaseModel.preview(address_id, mch_list, new ApiModel.CommonCallback<OrderConfirmBean>() {
            @Override
            public void onSuccess(OrderConfirmBean orderConfirmBean) {
                mRootView.onLoadSuccess(orderConfirmBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadFailed(errMsg);
            }
        });
    }

    public void list(String status, int page) {

        mBaseModel.list(status, page, new ApiModel.CommonCallback<OrderListBean>() {
            @Override
            public void onSuccess(OrderListBean beanList) {
                mRootView.onLoadListSuccess(beanList);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadListFailed(errMsg);
            }
        });
    }

    public void submit(String address_id, String mch_list, int use_integral, int payment) {

        mBaseModel.submit(address_id, mch_list, use_integral, payment, new ApiModel.CommonCallback<OrderSubmitResult>() {
            @Override
            public void onSuccess(OrderSubmitResult orderSubmitResult) {
                mRootView.onSubmitSuccess(orderSubmitResult);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onSubmitFailed(errMsg);
            }
        });
    }

    public void payBalance(String order_id, String parent_user_id, String condition) {

        mBaseModel.payBalance(order_id, parent_user_id, condition, new ApiModel.CommonCallback<OrderPayResultBalanceBean>() {
            @Override
            public void onSuccess(OrderPayResultBalanceBean orderPayResultBalanceBean) {
                mRootView.onPayBalanceSuccess(orderPayResultBalanceBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onPayBalanceFailed(errMsg);
            }
        });
    }

    public void payWX(String order_id, String parent_user_id, String condition,boolean gift) {

        mBaseModel.payWX(order_id, parent_user_id, condition,gift, new ApiModel.CommonCallback<OrderPayResultWxBean>() {
            @Override
            public void onSuccess(OrderPayResultWxBean orderPayResultWxBean) {
                mRootView.onPayWxSuccess(orderPayResultWxBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onPayWxFailed(errMsg);
            }
        });
    }

    public void detail(String order_id) {

        mBaseModel.detail(order_id, new ApiModel.CommonCallback<OrderDetailBean>() {
            @Override
            public void onSuccess(OrderDetailBean orderPayResultWxBean) {
                mRootView.onDetailSuccess(orderPayResultWxBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onDetailFailed(errMsg);
            }
        });
    }

    /**
     * 查询物流信息
     *
     * @param order_id
     * @param type     订单类型（1=普通订单 2=秒杀订单）
     */
    public void express(String order_id, String type) {

        mBaseModel.express(order_id, type, new ApiModel.CommonCallback<ExpressBean>() {
            @Override
            public void onSuccess(ExpressBean expressBean) {
                mRootView.onExpressSuccess(expressBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onExpressFailed(errMsg);
            }
        });
    }

    public void deleteOrder(String order_id) {

        mBaseModel.delete(order_id, new ApiModel.CommonCallback<String>() {
            @Override
            public void onSuccess(String orderPayResultWxBean) {
                mRootView.onDetailSuccess(null);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onDetailFailed(errMsg);
            }
        });
    }
}
